package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.BaseWhitelistIpsMapper;
import com.ruoyi.system.domain.BaseWhitelistIps;
import com.ruoyi.system.service.IBaseWhitelistIpsService;

/**
 * Web白名单Service业务层处理
 *
 * @author ruoyi
 * @date 2023-03-13
 */
@Service
public class BaseWhitelistIpsServiceImpl implements IBaseWhitelistIpsService {
    @Autowired
    private BaseWhitelistIpsMapper baseWhitelistIpsMapper;

    /**
     * 查询Web白名单
     *
     * @param id Web白名单主键
     * @return Web白名单
     */
    @Override
    public BaseWhitelistIps selectBaseWhitelistIpsById(Long id) {
        return baseWhitelistIpsMapper.selectBaseWhitelistIpsById(id);
    }

    /**
     * 查询Web白名单列表
     *
     * @param baseWhitelistIps Web白名单
     * @return Web白名单
     */
    @Override
    public List<BaseWhitelistIps> selectBaseWhitelistIpsList(BaseWhitelistIps baseWhitelistIps) {
        return baseWhitelistIpsMapper.selectBaseWhitelistIpsList(baseWhitelistIps);
    }

    /**
     * 新增Web白名单
     *
     * @param baseWhitelistIps Web白名单
     * @return 结果
     */
    @Override
    public int insertBaseWhitelistIps(BaseWhitelistIps baseWhitelistIps) {
        baseWhitelistIps.setCreateTime(DateUtils.getNowDate());
        return baseWhitelistIpsMapper.insertBaseWhitelistIps(baseWhitelistIps);
    }

    /**
     * 修改Web白名单
     *
     * @param baseWhitelistIps Web白名单
     * @return 结果
     */
    @Override
    public int updateBaseWhitelistIps(BaseWhitelistIps baseWhitelistIps) {
        baseWhitelistIps.setUpdateTime(DateUtils.getNowDate());
        return baseWhitelistIpsMapper.updateBaseWhitelistIps(baseWhitelistIps);
    }

    /**
     * 批量删除Web白名单
     *
     * @param ids 需要删除的Web白名单主键
     * @return 结果
     */
    @Override
    public int deleteBaseWhitelistIpsByIds(Long[] ids) {
        return baseWhitelistIpsMapper.deleteBaseWhitelistIpsByIds(ids);
    }

    /**
     * 删除Web白名单信息
     *
     * @param id Web白名单主键
     * @return 结果
     */
    @Override
    public int deleteBaseWhitelistIpsById(Long id) {
        return baseWhitelistIpsMapper.deleteBaseWhitelistIpsById(id);
    }

    @Override
    public Boolean findByIp(String lastIp) {
        BaseWhitelistIps baseWhitelistIps = new BaseWhitelistIps();
        baseWhitelistIps.setAddressIp(lastIp);
        List<BaseWhitelistIps> list = baseWhitelistIpsMapper.selectBaseWhitelistIpsList(baseWhitelistIps);
        return list.size() > 0 ? true : false;
    }
}
